package client.rmiManager;

//import java.util.Hashtable;

import java.net.UnknownHostException;
import java.rmi.Naming;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import server.object.CObject3D;
import server.universe.*;


public class RMIManager {

	private static RMIManager rmiManagerInstance;
	
	public static RMIManager rmiManagerInstance() {
		if(rmiManagerInstance == null) {
			rmiManagerInstance = new RMIManager();
		}
		
		return rmiManagerInstance;
	}
	
	private RMIManager() {
		
	}
	
    public UniverseFacadeRemote getUniverseFacade() {
        // Lookup the Remote Bean interface through JNDI
        Context initialContext;
		try {
			initialContext = getInitialContext();
			UniverseFacadeRemote facadeBean = null;
			String ipHouse = "192.168.1.12";
			String ipIfsic = "148.60.13.83";			
			String adresse = "rmi://"+ipIfsic+"/universe/";
			facadeBean = (UniverseFacadeRemote) initialContext.lookup(adresse);
			return facadeBean;
		} catch (NamingException e) {
			e.printStackTrace();
		}
		
        return null;
    }
    
    public CObject3D getCObject3D(String name){
    	// Lookup the Remote Bean interface through JNDI
        Context initialContext;
		try {
			initialContext = getInitialContext();
			CObject3D objectFacade = null;
			String ipHouse = "192.168.1.12";
			String ipIfsic = "148.60.13.83";			
			String adresse = "rmi://"+ipIfsic+"/universe/"+name;
			objectFacade = (CObject3D) initialContext.lookup(adresse);
			return objectFacade;
		} catch (NamingException e) {
			e.printStackTrace();
		}
		
        return null;
    }
	
    private static Context getInitialContext() throws NamingException {
        return new InitialContext();
    }
	
}
